package com.wxd.woff.table.glyf;

import com.wxd.woff.AbstractOTFDataStream;

import java.io.IOException;
import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: wangxindong
 * @date: 2018/9/2-10:13
 */
public abstract class AbstractGlyfDescript implements GlyphDescription {
	
	protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractGlyfDescript.class);

    // Flags describing a coordinate of a glyph.
    /**
     * if set, the point is on the curve.
     */
    public static final byte ON_CURVE = 0x01;
    /**
     * if set, the x-coordinate is 1 byte long.
     */
    public static final byte X_SHORT_VECTOR = 0x02;
    /**
     * if set, the y-coordinate is 1 byte long.
     */
    public static final byte Y_SHORT_VECTOR = 0x04;
    /**
     * if set, the next byte specifies the number of additional
     * times this set of flags is to be repeated.
     */
    public static final byte REPEAT = 0x08;
    /**
     * This flag as two meanings, depending on how the
     * x-short vector flags is set.
     * If the x-short vector is set, this bit describes the sign
     * of the value, with 1 equaling positive and 0 positive.
     * If the x-short vector is not set and this bit is also not
     * set, the current x-coordinate is a signed 16-bit delta vector.
     */
    public static final byte X_DUAL = 0x10;
    /**
     * This flag as two meanings, depending on how the
     * y-short vector flags is set.
     * If the y-short vector is set, this bit describes the sign
     * of the value, with 1 equaling positive and 0 positive.
     * If the y-short vector is not set and this bit is also not
     * set, the current y-coordinate is a signed 16-bit delta vector.
     */
    public static final byte Y_DUAL = 0x20;

    private int[] instructions;
    private final int contourCount;

    protected AbstractGlyfDescript(int numberOfContours, AbstractOTFDataStream bais) {
        contourCount = numberOfContours;

    }

    @Override
    public boolean isComposite() {
        return false;
    }

    @Override
    public int getContourCount() {
        return 0;
    }

    @Override
    public void resolve() {

    }

    protected void readInstructions(AbstractOTFDataStream bais, int count) throws IOException {
        instructions = bais.readUnsignedByteArray(count);
    }

    public int[] getInstructions() {
        return instructions;
    }

    public void setInstructions(int[] instructions) {
        this.instructions = instructions;
    }

    @Override
    public String toString() {
        return "AbstractGlyfDescript{" +
                "instructions=" + Arrays.toString(instructions) +
                ", contourCount=" + contourCount +
                '}';
    }
}
